﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Diagnostics;

namespace Axial.Tests
{
	[TestFixture]
	public class WhileTests : TestBase
	{
		[Test]
		public void SimpleTest()
		{
			string check =
@"while (a > b)
	a = 3;";
			check = VerifyMethodOutput("Simple", check);
		}
		public void Simple()
		{
			int a = 2, b = 1;
			while (a > b)
				a = 3;
		}

		[Test]
		public void ConditionsTest()
		{
			string check =
@"while (a == b)
	a = 3;
while (a != b)
	a = 3;
while (a > b)
	a = 3;
while (a >= b)
	a = 3;
while (a <= b)
	a = 3;
while (a < b)
	a = 3;";
			check = VerifyMethodOutput("Conditions", check);
		}
		public void Conditions()
		{
			int a = 2, b = 1;
			while (a == b)
				a = 3;
			while (a != b)
				a = 3;
			while (a > b)
				a = 3;
			while (a >= b)
				a = 3;
			while (a <= b)
				a = 3;
			while (a < b)
				a = 3;
		}

		[Test]
		public void OrTest()
		{
			string check =
@"while (a == b || c == 4)
	a = 15;";
			check = VerifyMethodOutput("Or", check);
		}
		public void Or()
		{
			int a = 2, b = 1, c = 3;
			while (a == b || c == 4)
				a = 15;
		}

		[Test]
		public void OrAndTest()
		{
			string check =
@"while (a == b || c == 4 && a == c)
	a = 15;";
			check = VerifyMethodOutput("OrAnd", check);
		}
		public void OrAnd()
		{
			int a = 2, b = 1, c = 3;
			while (a == b || c == 4 && a == c)
				a = 15;
		}

		[Test]
		public void AndTest()
		{
			string check =
@"while (a == b && c == 4)
	a = 15;";
			check = VerifyMethodOutput("And", check);
		}
		public void And()
		{
			int a = 2, b = 1, c = 3;
			while (a == b && c == 4)
				a = 15;
		}

		[Test]
		public void AndOrTest()
		{
			string check =
@"while (a == b && c == 4 || a > c)
	a = 15;";
			check = VerifyMethodOutput("AndOr", check);
		}
		public void AndOr()
		{
			int a = 2, b = 1, c = 3;
			while (a == b && c == 4 || a > c)
				a = 15;
		}

		[Test]
		public void AndOrWhileTest()
		{
			string check =
@"while (a == b && c == 4 || a < c)
	while (b == 2)
		a = 15;";
			check = VerifyMethodOutput("AndOrWhile", check);
		}
		public void AndOrWhile()
		{
			int a = 2, b = 1, c = 3;
			while (a == b && c == 4 || a < c)
				while (b == 2)
					a = 15;
		}

		[Test]
		public void AndOrWhileStatementTest()
		{
			string check =
@"while (a == b && c == 4 || a == c)
{
	while (b == 2)
		a = 15;
	c = 10;
}";
			check = VerifyMethodOutput("AndOrWhileStatement", check);
		}
		public void AndOrWhileStatement()
		{
			int a = 2, b = 1, c = 3;
			while (a == b && c == 4 || a == c)
			{
				while (b == 2)
					a = 15;
				c = 10;
			}
		}

		[Test]
		public void OrAndWhileTest()
		{
			string check =
@"while (a == b || c == 4 && a == c)
	while (b == 2)
		a = 15;";
			check = VerifyMethodOutput("OrAndWhile", check);
		}
		public void OrAndWhile()
		{
			int a = 2, b = 1, c = 3;
			while (a == b || c == 4 && a == c)
				while (b == 2)
					a = 15;
		}

		[Test]
		public void And3Test()
		{
			string check =
@"while (a == b && c == 4 && a == 2)
	a = 15;";
			check = VerifyMethodOutput("And3", check);
		}
		public void And3()
		{
			int a = 2, b = 1, c = 3;
			while (a == b && c == 4 && a == 2)
				a = 15;
		}

		[Test]
		public void Or3Test()
		{
			string check =
@"while (a == b || c == 4 || a == 2)
	a = 15;";
			check = VerifyMethodOutput("Or3", check);
		}
		public void Or3()
		{
			int a = 2, b = 1, c = 3;
			while (a == b || c == 4 || a == 2)
				a = 15;
		}

		[Test]
		public void VeryLongTest()
		{
			string check =
@"while (a == b && c != 4 && a > 2 && b < 3 && a >= c && c <= b && a == 3)
	a = 10;";
			check = VerifyMethodOutput("VeryLong", check);
		}
		public void VeryLong()
		{
			int a = 2, b = 1, c = 3;
			while (a == b && c != 4 && a > 2 && b < 3 && a >= c && c <= b && a == 3)
				a = 10;
		}

		[Test]
		public void VeryLongMixedTest()
		{
			string check =
@"while (a == b || c != 4 || a > 2 && b < 3 || a >= c && c <= b || a == 3)
	a = 10;";
			check = VerifyMethodOutput("VeryLongMixed", check);
		}
		public void VeryLongMixed()
		{
			int a = 2, b = 1, c = 3;
			while (a == b || c != 4 || a > 2 && b < 3 || a >= c && c <= b || a == 3)
				a = 10;
		}

		[Test]
		public void WhileWhileTest()
		{
			VerifyMethodOutput("WhileWhile",
@"while (a == 1)
	a = 2;
while (b == 2)
	b = 1;");
		}
		public void WhileWhile()
		{
			int a = 0;
			int b = 1;
			while (a == 1)
				a = 2;
			while (b == 2)
				b = 1;
		}

		[Test]
		public void ReturnTest()
		{
			VerifyMethodOutput("Return",
@"while (a < 5)
{
	b = b + 1;
	return;
}
a = a + 1;");
		}
		public void Return()
		{
			int a = 0;
			int b = 1;
			while (a < 5)
			{
				b++;
				return;
			}
			a++;
		}
	}
}
